<template>
    <div>
        <div class="titleLeft">
            <i class="iconfont icontongyong_dangqianweizhi"></i>
            <span>客户</span>
            <i class="el-icon-arrow-right"></i>
            <span >文件审核</span>
      </div>
       <section class="part">
            <h3>全部文件</h3>
            <div class="tabledata">
                <el-table :data="tableData" border>
                    <el-table-column v-for="(item, index) in tableCols" :key="index" :prop='item.prop' :label="item.label"></el-table-column>
                    <el-table-column  label="操作"  width="180">
                        <template slot-scope="scope">
                            <el-button v-if="scope.row.type == '1'" @click="preview(scope.row)" class="edit" type="text" size="small">预览</el-button>
                            <!-- <el-button v-else @click="downloadfile(scope.row)" class="edit" type="text" size="small">下载</el-button> -->
                            <a v-else class="downa" :href="downUrl +  scope.row.url">下载</a>
                            <!-- <el-button type="text" @click="agree(scope.row)" class="del" size="small">通过</el-button>
                            <el-button type="text" @click="disagree(scope.row)" class="del" size="small">驳回</el-button> -->
                        </template>
                    </el-table-column>
                </el-table>
            <el-pagination 
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page.sync="currentPage"
                :page-size="10"
                prev-text='上一页'
                next-text='下一页'
                layout="total, prev, pager, next"
                :total="total">
            </el-pagination>
            </div>
            
        </section>
        <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
    </div>
</template>

<script>
export default {
    data() {
        return {
            tableData: [],
            tableCols: [
                {label : '企业名称', prop:'companyName'},{label : '文件名称', prop:'name'}, {label : '上传用户', prop:'uploadUser'}, {label : '上传日期', prop:'createTime'}
            ],
            currentPage: 1,
            total: 0,
            dialogVisible: false,
            dialogImageUrl: '',
            downUrl: this.$viewImg
        }
    },
    mounted() {
        this.getTableData()
    },
    methods: {
        agree(row) {
            let param = {
                id: row.id,
                state: 2
            }
            this.$api.apiChangeState(param).then(res => {
                this.$message({
                    type: 'success',
                    message: '审核通过'
                })
                row.type = 1;
                // this.currentPage = 1
                // this.getTableData()
            })
        },
        disagree(row) {
            let param = {
                id: row.id,
                state: 3
            }
            this.$api.apiChangeState(param).then(res => {
                this.$message({
                    type: 'success',
                    message: '驳回成功'
                })
                this.currentPage = 1
                this.getTableData()
            })
        },
        downloadfile(row) {
            let param = {
                fileType: row.type,
                fileUrl: row.url,
                name: row.name
            }
            this.$api.apiDownFile(param).then(res => {
                
            })
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.currentPage = val
           this.getTableData()
        },
        getTableData() {
            let param = {
                state: 1,
                page: this.currentPage
            }
            this.$api.apiGetFiles(param).then(res => {
                if(res.data != null) {
                    this.tableData = res.data.data
                    this.tableData.forEach(item => {
                        item.createTime = this.$moment(item.createTime).format('YYYY-MM-DD')
                    })
                    this.total = res.data.pageInfo.total
                }
                
            })
        },
        preview(row) {
            
            this.dialogImageUrl = this.$viewImg + row.url
            this.dialogVisible = true
        }
    }
}
</script>
<style lang="scss">
    .downa {
        margin-right: 10px; color: #409EFF;font-size: 12px
    }
    .downa:hover, .edit:hover {
        cursor: pointer;
    }
</style>